import {Url} from "./Urls";

export class AppConfig {
    static init = false;
    static URLS: Map<string, Url> = new Map<string, Url>();

    static startInit():Promise<any> {
        return fetch('/server-coder.json').then(res => res.json()).catch(e => console.error(e)).then(
            (urls) => {
                if (urls.urls) {
                    for (let urlKey in urls.urls) {
                        if (urls.urls.hasOwnProperty(urlKey)) {
                            this.URLS.set(urlKey,
                                new Url(`${urls.protocol}://${urls.host}:${urls.port}${urls.contextPath}${urls.urls[urlKey].url}`, urls.urls[urlKey].name, urls.urls[urlKey].method,
                                    urls.urls[urlKey].url))
                        }
                    }
                }
                this.init = true;
            }
        )
    }
}